package com.springboot.redis.service.impl;

import com.springboot.redis.entity.Customer;
import com.springboot.redis.mapper.CustomerMapper;
import com.springboot.redis.service.CustomerService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@CacheConfig(cacheNames = "customer")
public class CustomerServiceImpl implements CustomerService {

    @Resource
    private CustomerMapper customerMapper;
    @Override
    @Cacheable(key = "#root.methodName")
    public List<Customer> queryAll() {
        return customerMapper.selectList(null);
    }

    @Override
//    @CachePut(key = "#customer.customerId")
    @CacheEvict(allEntries=true)
    public void addOne(Customer customer) {
        customerMapper.insert(customer);
    }
    
}